/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nl.maxato.services;

import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

import nl.maxato.domain.Athlete;
import nl.maxato.domain.Discipline;

/**
 *
 * @author Danny
 */
public class CalculateDisciplines {

    List<Athlete> athletes;
    List<Discipline> disciplines;
    Discipline discipline;
    Athlete athlete;
    CalculateGeneralData bag;

    public CalculateDisciplines() {
        disciplines = new ArrayList<Discipline>();
        athletes = new ArrayList<Athlete>();
        bag = new CalculateGeneralData();
        init();
    }

    public final void init() {
        //100 meter
        discipline = new Discipline(1, 3, 1, 2, 3, 1, 4, 2, 1, 0, 3, 3);
        disciplines.add(discipline);
        //200 meter
        discipline = new Discipline(4, 3, 1, 2, 3, 1, 4, 2, 1, 0, 3, 2);
        disciplines.add(discipline);
        //400 meter
        discipline = new Discipline(6, 3, 1, 2, 3, 2, 4, 2, 1, 0, 3, 2);
        disciplines.add(discipline);
        //110 meter horden
        discipline = new Discipline(23, 3, 1, 2, 2, 1, 4, 3, 2, 0, 3, 2);
        disciplines.add(discipline);
        //400 meter horden
        discipline = new Discipline(25, 3, 1, 2, 2, 2, 3, 3, 2, 0, 3, 2);
        disciplines.add(discipline);
        //800 meter
        discipline = new Discipline(8, 3, 1, 2, 2, 3, 4, 2, 1, 0, 3, 2);
        disciplines.add(discipline);
        //1500 meter
        discipline = new Discipline(11, 3, 1, 2, 1, 4, 3, 2, 1, 0, 3, 2);
        disciplines.add(discipline);
        //3000 meter steeplechase
        discipline = new Discipline(19, 3, 1, 2, 1, 4, 3, 2, 1, 0, 3, 2);
        disciplines.add(discipline);
        //5000 meter
        discipline = new Discipline(14, 3, 1, 2, 1, 4, 3, 1, 0, 0, 3, 2);
        disciplines.add(discipline);
        //10000 meter
        discipline = new Discipline(15, 3, 1, 2, 1, 4, 3, 1, 0, 0, 3, 2);
        disciplines.add(discipline);
        //Marathon
        discipline = new Discipline(53, 3, 1, 2, 1, 4, 3, 1, 0, 0, 3, 2);
        disciplines.add(discipline);
        //10Km Race Walk
        discipline = new Discipline(46, 3, 1, 2, 1, 4, 2, 2, 0, 0, 3, 3);
        disciplines.add(discipline);
        //20Km Race Walk
        discipline = new Discipline(47, 3, 1, 2, 1, 4, 2, 2, 0, 0, 3, 3);
        disciplines.add(discipline);
        //50Km Race Walk
        discipline = new Discipline(72, 3, 1, 2, 1, 5, 1, 2, 0, 0, 3, 3);
        disciplines.add(discipline);
        //High Jump
        discipline = new Discipline(26, 3, 1, 2, 1, 0, 1, 3, 4, 0, 2, 3);
        disciplines.add(discipline);
        //Pole Vault
        discipline = new Discipline(27, 3, 1, 2, 1, 0, 1, 4, 4, 0, 3, 3);
        disciplines.add(discipline);
        //Long Jump
        discipline = new Discipline(28, 3, 1, 2, 1, 0, 3, 3, 4, 0, 2, 3);
        disciplines.add(discipline);
        //Triple Jump
        discipline = new Discipline(29, 3, 1, 2, 1, 0, 2, 4, 4, 0, 2, 3);
        disciplines.add(discipline);
        //Shot Put
        discipline = new Discipline(31, 3, 1, 2, 5, 0, 1, 2, 0, 4, 2, 2);
        disciplines.add(discipline);
        //Discus Throw
        discipline = new Discipline(32, 3, 1, 2, 4, 0, 1, 3, 0, 4, 2, 2);
        disciplines.add(discipline);
        //Hammer Throw
        discipline = new Discipline(33, 3, 1, 2, 4, 0, 1, 3, 0, 4, 2, 2);
        disciplines.add(discipline);
        //Javelin Throw
        discipline = new Discipline(34, 3, 1, 2, 4, 0, 2, 3, 0, 4, 2, 3);
        disciplines.add(discipline);
        //Relays 4x100
        discipline = new Discipline(80, 3, 1, 3, 3, 1, 5, 3, 1, 0, 0, 0);
        disciplines.add(discipline);
        //Relays 4x400
        discipline = new Discipline(90, 3, 1, 3, 3, 3, 4, 3, 1, 0, 0, 0);
        disciplines.add(discipline);
    }

    public List<Athlete> calculateDiscipline(List<Athlete> athleteList, int typeOfDiscipline, boolean form, boolean care, boolean experience) {
        int value;
                int waarde;
        int formInt =0;
        int careInt=0;
        int experienceInt=0;
        ArrayList<Athlete> atleetList = new ArrayList<Athlete>();
        for (int q = 0; q < disciplines.size(); q++) {
            if (disciplines.get(q).getTypeOfDiscipline() == typeOfDiscipline) {
                discipline = disciplines.get(q);
            }
        }
        for (int i = 0; i < athleteList.size(); i++) {
                        if(form){
                formInt = athleteList.get(i).getForm();
            }
            if(care){
                careInt = athleteList.get(i).getCare();
            }
            if(experience){
                experienceInt = athleteList.get(i).getExperience();
            }
            value = (discipline.getExperience() * experienceInt)
                    + (discipline.getForm() * formInt)
                    + (discipline.getCare() * careInt)
                    + (discipline.getStrenght() * athleteList.get(i).getStrenght())
                    + (discipline.getStamina() * athleteList.get(i).getStamina())
                    + (discipline.getSpeed() * athleteList.get(i).getSpeed())
                    + (discipline.getAgility() * athleteList.get(i).getAgility())
                    + (discipline.getJump() * athleteList.get(i).getJump())
                    + (discipline.getThrowing() * athleteList.get(i).getThrowing())
                    + (discipline.getSpecialty1() * athleteList.get(i).getSpecialty1())
                    + (discipline.getSpecialty2() * athleteList.get(i).getSpecialty2());
            athlete = athleteList.get(i);
            athlete.setTotalValueDiscipline(value);
            atleetList.add(athlete);
        }
        return atleetList;
    }

    public List<Discipline> calculateSpecialty(int strenght, int stamina, int speed, int agility, int jump, int throwing, ResourceBundle rb) {
        List<Discipline> ld = new ArrayList<Discipline>();
        for (int a = 0; a < disciplines.size(); a++) {
            int totaalwaarde = 0;
            String disciplineNaam = bag.getDisciplineToString(disciplines.get(a).getTypeOfDiscipline(), rb);
            totaalwaarde = (disciplines.get(a).getStrenght() * strenght) + (disciplines.get(a).getStamina() * stamina) + (disciplines.get(a).getSpeed() * speed) + (disciplines.get(a).getAgility() * agility) + (disciplines.get(a).getJump() * jump) + (disciplines.get(a).getThrowing() * throwing);
            Discipline dcp = new Discipline(disciplineNaam, totaalwaarde);
            ld.add(dcp);
        }
        return ld;
    }

    public List<Athlete> calculateNewDiscipline(List<Athlete> athleteList, int typeOfDiscipline, boolean form, boolean care, boolean experience) {
        int waarde;
        int formInt =0;
        int careInt=0;
        int experienceInt=0;
        ArrayList<Athlete> atleetList = new ArrayList<Athlete>();
        for (int q = 0; q < disciplines.size(); q++) {
            if (disciplines.get(q).getTypeOfDiscipline() == typeOfDiscipline) {
                discipline = disciplines.get(q);
            }
        }
        for (int i = 0; i < athleteList.size(); i++) {
            if(form){
                formInt = athleteList.get(i).getForm();
            }
            if(care){
                careInt = athleteList.get(i).getCare();
            }
            if(experience){
                experienceInt = athleteList.get(i).getExperience();
            }
            waarde = (discipline.getExperience() * experienceInt)
                    + (discipline.getForm() * formInt)
                    + (discipline.getCare() * careInt)
                    + (discipline.getStrenght() * athleteList.get(i).getStrenght())
                    + (discipline.getStamina() * athleteList.get(i).getStamina())
                    + (discipline.getSpeed() * athleteList.get(i).getSpeed())
                    + (discipline.getAgility() * athleteList.get(i).getAgility())
                    + (discipline.getJump() * athleteList.get(i).getJump())
                    + (discipline.getThrowing() * athleteList.get(i).getThrowing());
            athlete = athleteList.get(i);
            athlete.setTotalValueDiscipline(waarde);
            atleetList.add(athlete);
        }
        return atleetList;
    }

//    public String getBestAthlete(int discipline, List<Athlete> adf) {
//        List<Athlete> atleetList = new ArrayList<Athlete>();
//        atleetList = calculateDiscipline(adf, discipline);
//        int biggestValue = 0;
//        int index = 0;
//        for (int i = 0; i < atleetList.size(); i++) {
//            if(atleetList.get(i).getTotalValueDiscipline() > biggestValue){
//                biggestValue = atleetList.get(i).getTotalValueDiscipline();
//                index = i;
//            }
//        }
//        return atleetList.get(index).getSurname()+" "+ atleetList.get(index).getName()+ " - "+ atleetList.get(index).getTotalValueDiscipline();
//    }
}
